package com.oocl.FTP;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import com.sun.imageio.plugins.common.InputStreamAdapter;

public class FtpServer {

	public static void main(String[] args) throws Exception
	{
		//final String PATH="ftp/";
		ServerSocket server=new ServerSocket(8001);
		while(true)
		{
			Socket socket=server.accept();
			
			OutputStream out=socket.getOutputStream();
			out.write("请输入指令:\n".getBytes());
			
			InputStream in=socket.getInputStream();
			BufferedReader reader=new BufferedReader(new InputStreamReader(in));
			
			String filename=reader.readLine();
			
			File file = new File(filename);  
		    if (!file.getParentFile().exists()) {  
		        file.getParentFile().mkdirs();  
		    }
			OutputStream fout=new FileOutputStream(file);
			
			byte[] buf=new byte[4];
			int len=0;
			while((len=in.read(buf))!=-1)
			{
				fout.write(buf,0,len);
			}
			
			reader.close();
			out.close();
			fout.close();
			socket.close();
		}
	}

}
